<template>
    <view>
        <view v-if="is_search_list == true">
            <view v-if="searchItemList.length > 0">
                <view v-for="(info, key) in searchItemList" :key="key">
                    <itemInfo :buy_mode="buy_mode" :cart_item_info="cart_item_list && cart_item_list[info.item_id] ? cart_item_list[info.item_id] : null"
                        :itemAttrDialogShow="itemAttrDialogShow" :itemInfoDialogShow="itemInfoDialogShow"
                        :itemAttrCartUpdate="itemAttrCartUpdate" :seller_user_id="seller_user_id" :item_info="info"
                        class_page="padding-tb-20 padding-lr-30"></itemInfo>
                </view>
            </view>
            <view v-else-if="is_searching">
                <emptyList empty_list_title="搜索无结果"></emptyList>
            </view>
        </view>
        <view v-else-if="item_list_info.list_key">
            <verticalNav v-if="item_list_info.list_left.length>0" :height_sub="seller_user_id?280:380" :item_list_tab="item_list_tab"
                :item_list_info.sync="item_list_info" :scroll_y.sync="vertical_nav_scroll_y">
                <template #item_left="data">
                    {{data.item.name}}
                </template>
                <template #list_right="data">
                    <view v-for="(info, key) in data.list" :key="key">
                        <itemInfo :buy_mode="buy_mode" :cart_item_info="cart_item_list && cart_item_list[info.item_id] ? cart_item_list[info.item_id] : null"
                            :itemAttrDialogShow="itemAttrDialogShow" :itemInfoDialogShow="itemInfoDialogShow"
                            :itemAttrCartUpdate="itemAttrCartUpdate" :seller_user_id="seller_user_id" :item_info="info"
                            class_page="padding-tb-20 padding-right-30"></itemInfo>
                    </view>
                </template>
            </verticalNav>
            <emptyList v-else :empty_list_title="seller_user_id?'还没有商品':''">
                <template #content>
                    <view v-if="!seller_user_id" class="line-height-16em">
                        <view>没有已审核且已上架的分类、商品，请检查：</view>
                        <view>1. 有没有添加商品。</view>
                        <view>2. 商家或企业有没有缴年费。</view>
                        <view>3. 如果是全国邮寄，商家或企业有没有缴保证金。</view>
                        <view>4. 分类是不是审核了、是不是上架了。</view>
                        <view>5. 商品是不是审核了、是不是上架了。</view>
                        <view>6. 商品属性是不是审核了、是不是上架了。</view>
                        <view>7. 分类和商品对应的商家、企业类型是不是一致</view>
                    </view>
                </template>
            </emptyList>
        </view>
        <view v-else-if="!seller_user_id && item_list_info.item_list && item_list_info.item_list.length>0" class="bg-white">
            <view class="margin-lr-20 padding-bottom-20">
                <view v-if="
                    !item_list_info.form.user_visible_type ||
                    (item_list_info.form.user_visible_type==1 && info.is_user_visible == 1) ||
                    (item_list_info.form.user_visible_type==2 && info.is_user_visible == 0)
                "
                    class="flex flex-direction padding-bottom-20" v-for="(info, key) in item_list_info.item_list" :key="key">
                    <view class="flex">
                        <itemInfo :buy_mode="buy_mode" :cart_item_info="cart_item_list && cart_item_list[info.item_id] ? cart_item_list[info.item_id] : null"
                            :itemAttrDialogShow="itemAttrDialogShow" :itemInfoDialogShow="itemInfoDialogShow"
                            :itemAttrCartUpdate="itemAttrCartUpdate" :seller_user_id="seller_user_id" style="width: 546rpx;"
                            :item_info="info" class_page="padding-tb-20"></itemInfo>
                        <view class="flex flex-sub flex-direction padding-left-10 margin-top-10" style="width: 154rpx;">
                            <view class="margin-top-10">
                                <view class="cu-tag bg-red" v-if="info.item_open_status == 0">商品下架</view>
                                <view class="cu-tag bg-nddyny" v-if="info.item_open_status == 1">商品上架</view>
                            </view>
                            <view class="margin-top-10">
                                <view class="cu-tag bg-red" v-if="info.item_attr_open_status == 0">属性下架</view>
                                <view class="cu-tag bg-nddyny" v-if="info.item_attr_open_status == 1">属性上架</view>
                            </view>
                            <view class="margin-top-10">
                                <view class="cu-tag bg-red" v-if="info.item_audit_status == 0">商品审核中</view>
                                <view class="cu-tag bg-nddyny" v-if="info.item_audit_status == 1">商品已审核</view>
                                <view class="cu-tag bg-red" v-if="info.item_audit_status == 2">商品审核失败</view>
                            </view>
                            <view class="margin-top-10">
                                <view class="cu-tag bg-red" v-if="info.item_attr_audit_status == 0">属性审核中</view>
                                <view class="cu-tag bg-nddyny" v-if="info.item_attr_audit_status == 1">属性已审核</view>
                                <view class="cu-tag bg-red" v-if="info.item_attr_audit_status == 2">属性审核失败</view>
                            </view>
                        </view>
                    </view>
                    <view style="margin-top: -10rpx;">
                        <view class="flex">
                            <view class="flex" v-if="$store.state.user.identity_info.is_seller==1&&$store.state.user.identity_info.is_firm==1">
                                <view>
                                    <view class="cu-capsule margin-right-10">
                                        <view class="cu-tag" :class="[info.item_is_seller==1?'bg-nddyny':'']" v-if="$store.state.user.identity_info.is_seller==1">商家</view>
                                    </view>
                                </view>
                                <view>
                                    <view class="cu-capsule margin-right-10">
                                        <view class="cu-tag" :class="[info.item_is_firm==1?'bg-nddyny':'']" v-if="$store.state.user.identity_info.is_firm==1">企业</view>
                                    </view>
                                </view>
                            </view>
                            <view>
                                <view class="cu-capsule margin-right-10">
                                    <view class='cu-tag bg-nddyny'>
                                        排序
                                    </view>
                                    <view class="cu-tag line-nddyny">
                                        {{info.item_sort}}
                                    </view>
                                </view>
                            </view>
                            <view>
                                <view class="cu-capsule">
                                    <view class='cu-tag bg-nddyny'>
                                        上架时间
                                    </view>
                                    <view class="cu-tag line-nddyny">
                                        {{info.open_start_time | timeFormat('hh:mm')}}
                                        <text class="padding-lr-4">-</text>
                                        <text v-if="info.open_end_time==0">24:00</text>
                                        <text v-else>{{info.open_end_time | timeFormat('hh:mm')}}</text>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="flex">
                            <view class="margin-right-10 margin-top-10" v-for="(name, key) in $store.state.user.dict_to_shop_same_city_express"
                                :key="key" v-if="name">
                                <view class="cu-capsule">
                                    <view class='cu-tag' :class="[info[key] == 1?'bg-nddyny':'bg-red']">
                                        {{name}}
                                    </view>
                                    <view v-if="info[key] == 1" class="cu-tag line-nddyny">
                                        {{info[key.substr(3)+'_pack_price'] | floor}}
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="cu-capsule margin-top-10" v-if="info.send_channel_id>0">
                            <view class='cu-tag bg-nddyny'>
                                发货渠道
                            </view>
                            <view class="cu-tag line-nddyny">
                                {{sendChannelList?sendChannelList[info.send_channel_id]:info.send_channel_id}}
                            </view>
                        </view>
                    </view>
                    <view>
                        <view class="cu-capsule padding-right-10 margin-top-10">
                            <view class="cu-tag line-nddyny">
                                {{seller_item_category[info.item_category_1]}}
                            </view>
                        </view>
                        <view v-if="info.attr_key_1" class="cu-tag line-nddyny margin-top-10">{{info.attr_key_1}}</view>
                        <view v-if="info.attr_key_2" class="cu-tag line-nddyny margin-top-10">{{info.attr_key_2}}</view>
                        <view v-if="info.attr_key_3" class="cu-tag line-nddyny margin-top-10">{{info.attr_key_3}}</view>
                        <view v-for="(info, key) in info.item_type_list" :key="key" :class="[info.item_type_open_status==1&&info.item_type_audit_status==1?'bg-nddyny':'bg-red']"
                            class="cu-tag margin-top-10">{{info.item_type_name}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view v-else>
            <emptyList>
                <template #content :empty_list_title="seller_user_id?'还没有商品':''">
                    <view v-if="!seller_user_id" class="line-height-16em">
                        <view>没有商品，请检查：</view>
                        <view>1. 没有添加商品。</view>
                        <view>2. 商家或企业有没有缴年费。</view>
                    </view>
                </template>
            </emptyList>
        </view>
    </view>
</template>

<script>
    import itemInfo from './itemInfo.vue';
    export default {
        components: {
            itemInfo,
        },
        props: [
            'buy_mode',
            'seller_user_id',
            'cart_item_list',
            'item_list_tab',
            'is_search_list',
            'search_value',
            'item_list_info',
            'itemInfoDialogShow',
            'itemAttrDialogShow',
            'itemAttrCartUpdate',
            'vertical_nav_scroll_y'
        ],
        data() {
            return {
                seller_item_category: this.$dict.seller_item_category,
                is_searching: false,
            };
        },
        computed: {
            sendChannelList() {
                if (!this.item_list_info.send_channel_list) {
                    return;
                }
                let send_channel_list = {};
                this.item_list_info.send_channel_list.forEach(info => {
                    send_channel_list[info.send_channel_id] = info.name
                })
                return send_channel_list;
            },
            searchItemList() {
                let search_value = '';
                if (!this.search_value) {
                    this.is_searching = false;
                    return [];
                } else {
                    this.is_searching = true;
                    search_value = this.search_value.toLowerCase();
                }
                let item_list_object = {};
                let item_list_array = [];
                let page_item_list = this.item_list_info.list_right || this.item_list_info.item_list;
                page_item_list.forEach(info => {
                    if (item_list_object[info.item_id]) {
                        return;
                    }
                    let item_name = info.item_name.toLowerCase();
                    let item_content = info.content.toLowerCase();
                    if (item_name.search(search_value) != -1 ||
                        item_content.search(search_value) != -1
                    ) {
                        item_list_object[info.item_id] = info;
                    }
                })
                item_list_array = Object.values(item_list_object);
                this.$nddyny.array.sort(item_list_array, 'item_sort', 'item_id');
                return item_list_array;
            }
        },
    }
</script>
